/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.component.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.uml2.uml.Slot;

import com.cea.papyrus.core.PapyrusMessages;
import com.cea.papyrus.core.PapyrusPlugin;
import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.editor.mouseoveraction.ActionHandleManager;
import com.cea.papyrus.core.editpart.FeatureListEditPart;
import com.cea.papyrus.core.figures.IconFigure;
import com.cea.papyrus.core.ui.dialogs.PapyrusMessageDialog;
import com.cea.papyrus.diagram.deployment.figure.ArtifactISFigure;
import com.cea.papyrus.diagram.deployment.figure.FeatureContainerFigure;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * Manages a slot list.
 * 
 * @author Gilles Cannenterre
 * @since 22 janv. 07
 */
public class SlotListEditPart extends FeatureListEditPart {

	/**
	 * Constructor. Create a list accepting ExtensionPoint.
	 * 
	 * @param modelManager the model manager
	 * @param graphnode the graphnode
	 */
	public SlotListEditPart(GraphNode graphnode,ModelManager modelManager) {
		super(graphnode, Slot.class, modelManager);
	}

	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	protected IFigure createFigure() {
		return new FeatureContainerFigure();
	}

	/**
	 * 
	 */
	@Override
	protected void refreshVisuals() {		
		FeatureContainerFigure f = (FeatureContainerFigure) getFigure();
		f.setBackgroundColor(PapyrusPlugin.colorManager.get(getGraphNode().getContainer().getBackgroundColor()));
		
		IFigure parentFigure = ((GraphicalEditPart) getParent()).getFigure();
		
		// Shape presentation
		if (parentFigure instanceof IconFigure) {
			return;
		}	
		if (elementType == org.eclipse.uml2.uml.Slot.class) {
			if( parentFigure instanceof ArtifactISFigure){
				((ArtifactISFigure) parentFigure).addFeatureContainer(f);
			}
		}		
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.common.editpart.FeatureListEditPart#createEditPolicies()
	 */
	/**
	 * 
	 */
	@Override
	protected void createEditPolicies() {
		super.createEditPolicies();
	
		// Install mouse hover
		ActionHandleManager actionMngr = new ActionHandleManager(this);
		try{
			actionMngr.addTool(PapyrusPlugin.creationToolFactory.getCombinedTemplateCreationToolEntry(
					PapyrusMessages.AddSlotCommand_Label
					, PapyrusMessages.AddSlotCommand_Description
					, Slot.class
					, null)
					, PositionConstants.EAST);
		}
		catch (Exception e) {
			PapyrusMessageDialog.display(e.getMessage(), e);
		}
	}
}